package com.javastar.common.utils;

import cn.hutool.json.JSONUtil;
import com.javastar.common.exception.AssertUtil;
import com.javastar.common.exception.ErrorCode;
import com.javastar.common.result.Result;

import javax.servlet.http.HttpServletResponse;

/**
 * 响应输出工具类
 *
 * @author zxx
 * @date 2023/7/25
 */
public class ResponseUtil {
    public static void write(HttpServletResponse response, Result result) {
        try {
            response.setContentType("text/json;charset=utf-8");
            response.getWriter().write(JSONUtil.toJsonStr(result));
        } catch (Exception e) {
            e.printStackTrace();
            AssertUtil.error(ErrorCode.INTERNAL_SERVER_ERROR);
        }
    }
}
